package so.shanku.essential.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import so.shanku.essential.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/9/6.
 * 男士品牌
 */
public class ManBrandFragment extends BaseFragment {
	/**
	 * 头部标题
	 */

//	@ViewInject(R.id.tv_manbrand_head)
//	private TextView tv_manbrand_head;
	@ViewInject(R.id.rg_man_brand)
	private RadioGroup rg_man_brand;
	/**
	 * 保存点击过得fragment
	 */
	private List<BaseFragment> fragments = new ArrayList<BaseFragment>();

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.activity_man_brand, container, false);
		initCompont(view);
	//	tv_manbrand_head.setText(ShoppingBrandFragment.brandName);
		replaceView(new ManBrandHotFragment());
		initCheck();
		return view;
	}
	public void initCompont(View view) {
		ViewUtils.inject(this, view);
	}
	public void initCheck() {
		rg_man_brand.setOnCheckedChangeListener(
				new RadioGroup.OnCheckedChangeListener() {
					@Override
					public void onCheckedChanged(RadioGroup group, int checkedId) {
						// TODO Auto-generated method stub
						fragments.clear();
						for (int i = 0; i < group.getChildCount(); i++) {
							RadioButton radioButton = (RadioButton) group.getChildAt(i);
							if (radioButton.getId() == checkedId) {
								switch (i) {
									case 0:
										replaceView(new ManBrandHotFragment());
										break;
									case 1:
										replaceView(new ManBrandListFragment());
										break;

								}
							}

						}

					}
				}
		);

	}

	private void replaceView(Fragment fragment) {
		FragmentTransaction t = this.getFragmentManager().beginTransaction();
		t.replace(R.id.linearlayout_manbrand, fragment);
		t.commit();
	}
}


